package com.jy.rhin.infra.repo.node.query;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.jy.framework.base.entity.Page;
import com.jy.rhin.infra.repo.document.validation.mapper.DocumentValidationFileMapper;
import com.jy.rhin.infra.repo.document.validation.po.DocumentValidationFilePo;
import com.jy.rhin.sdk.dto.document.DocumentValidationFileDto;
import com.jy.rhin.sdk.dto.document.query.DocumentValidationFileRespDto;
import com.jy.starter.repository.utils.PageUtils;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
*
*/
@Slf4j
@Service
public class NodeAuthenticationHandler {

@Resource
private DocumentValidationFileMapper documentValidationFileMapper;

public Page<DocumentValidationFileDto> getValidationFilePage(DocumentValidationFileRespDto dto) {

    QueryWrapper<DocumentValidationFilePo> entryQueryWrapper = new QueryWrapper<>();
    entryQueryWrapper.lambda()
            .like(!StringUtils.isEmpty(dto.getFileName()), DocumentValidationFilePo::getFileName, dto.getFileName())
            .like(!StringUtils.isEmpty(dto.getFileType()), DocumentValidationFilePo::getFileType, dto.getFileType())
            .eq(!StringUtils.isEmpty(dto.getState()), DocumentValidationFilePo::getState, dto.getState())
            .orderByDesc(DocumentValidationFilePo::getUploadTime);
    com.baomidou.mybatisplus.extension.plugins.pagination.Page<DocumentValidationFilePo> page = new com.baomidou.mybatisplus.extension.plugins.pagination.Page<>(dto.getPageNo(), dto.getPageSize(), true);
    com.baomidou.mybatisplus.extension.plugins.pagination.Page<DocumentValidationFilePo> selectResult = documentValidationFileMapper.selectPage(page, entryQueryWrapper);
    return PageUtils.page(selectResult, this::toDto);
}


private DocumentValidationFileDto toDto(DocumentValidationFilePo po) {
    DocumentValidationFileDto dto = new DocumentValidationFileDto();
    BeanUtils.copyProperties(po, dto);
    return dto;
}


}
